<script setup lang="ts">
// 获取屏幕边界到安全距离
const {safeAreaInsets} = uni.getWindowInfo()

const onClickScan = () => {
  console.log('点击扫码')
  // 允许从相机和相册扫码
  uni.scanCode({
    success: function (res) {
      console.log('条码类型：' + res.scanType);
      console.log('条码内容：' + res.result);
      // res.result包含了扫码信息
      // 物资盘点，可使用这个结果查询物资信息，跳转到物资页面，传递扫码信息
    }
  });
}

</script>

<template>
  <view class="navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
    <!-- logo文字 -->
    <view class="logo">
      <view class="logo-image">
        <text>跳跳商城</text>
      </view>
      <text class="logo-text">新鲜 · 亲民 · 快捷</text>
    </view>
    <!-- 搜索条 -->
    <view class="search" @click="onClickScan">
      <text class="icon-search">搜索商品</text>
      <text class="icon-scan"></text>
    </view>
  </view>
</template>

<style scoped lang="scss">
/* 自定义导航条 */
.navbar {
  background-color: #00a8a0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.logo {
  display: flex;
  align-items: center;
  height: 64rpx;
  padding-left: 30rpx;
  padding-top: 20rpx;

}

.logo-image {
  width: 166rpx;
  height: 39rpx;
  font-size: 40rpx;
  color: white;
  display: flex;
  justify-items: center;
  align-items: center;
  font-family: 华文隶书, serif;
}

.logo-text {
  flex: 1;
  line-height: 28rpx;
  color: #fff;
  margin: 2rpx 0 0 20rpx;
  padding-left: 20rpx;
  border-left: 1rpx solid #fff;
  font-size: 26rpx;
}

.search {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10rpx 0 26rpx;
  height: 64rpx;
  margin: 16rpx 20rpx;
  color: #fff;
  font-size: 28rpx;
  border-radius: 32rpx;
  background-color: rgba(255, 255, 255, 0.5);
}

.icon-search {
  margin-right: 10rpx;
}

.icon-scan {
  font-size: 30rpx;
  padding: 15rpx;
}
</style>
